#include <iostream>
#include <vector>
using namespace std;
 struct TreeNode {
    int val;
    TreeNode *left;
    TreeNode *right;
    TreeNode(int x) : val(x), left(NULL), right(NULL) {}
};
void show_tree_node(vector<vector<int >> &v, int level, TreeNode * node){
    if(node == NULL){
        return;
    }
    int size = v.size();
    if(level > (size-1)){
        vector<int >* subV = new vector<int >();
        subV->push_back(node->val);
        v.push_back(*subV);
    }else{
        v[level].push_back(node->val);
    }
    show_tree_node(v,level+1, node->left);
    show_tree_node(v,level+1, node->right);
}
 /**
  * 二叉树的层次遍历
  * @param root
  * @return
  */
vector<vector<int>> levelOrder(TreeNode* root) {
    vector<vector<int >> * rv = new vector<vector<int >>;
    show_tree_node(*rv, 0,root);
    return *rv;
}

int main71(){
    TreeNode node1 = {3};
    TreeNode node2 = {9};
    TreeNode node3 = {20};
    node1.left = &node2;
    node1.right = &node3;
    TreeNode node5 = {15};
    TreeNode node6 = {7};
    node3.left = &node5;
    node3.right = &node6;

    vector<vector<int>> rv = levelOrder(&node1);

    for(vector<int> v : rv){
        for(int x : v){
            cout << x<<",";
        }
        cout<<endl;
    }
    return 0;
}